<template>
	<view style="background-color: #f1f1f1;height: 100vh;">
		<view class="two">
			<u--form :model="form" ref="uForm" :rules="rules">
				<view class="two-one1">
					<view class="two-oneLeft1">单据号 :</view>
					<view class="two-oneRight1">{{YSNUM}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">材检号 :</view>
					<view class="two-oneRight1">{{dataForm.YCJH}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">材质 :</view>
					<view class="two-oneRight1">{{dataForm.YCZ}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">规格 :</view>
					<view class="two-oneRight1">{{dataForm.YGG}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">申请人 :</view>
					<view class="two-oneRight1">{{dataForm.CREUSRDES}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">申请日期 :</view>
					<view class="two-oneRight1">{{dataForm.CREDAT}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">试样项目 :</view>
					<view class="two-oneRight1">{{dataForm.YITMREFNUM}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">试样名称 :</view>
					<view class="two-oneRight1">{{dataForm.YITMREF}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">数量 :</view>
					<view class="two-oneRight1">{{dataForm.YQTY}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">试样尺寸 :</view>
					<view class="two-oneRight1">{{dataForm.YSAMPGG}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">试样方向 :</view>
					<view class="two-oneRight1">{{dataForm.YSAMPFX}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">试样位置 :</view>
					<view class="two-oneRight1">{{dataForm.YSAMPLOC}}</view>
				</view>
				<view class="two-one1">
					<view class="two-oneLeft1">特殊说明 :</view>
					<view class="two-oneRight1">{{dataForm.YDES}}</view>
				</view>
			</u--form>
		</view>
		<div >
			<view class="four-item">
				<u-button class="rgzxBox-btn2" type="primary" v-show="this.syqrFlg"
				@click="submit(3)" >收样确认</u-button>
			</view>
		</div>
	</view>
</template>

<script>
	import { format } from 'date-fns';
	import * as dd from 'dingtalk-jsapi'

	export default {
		data() {
			return {
				tableDataAll:[],
				syqrFlg:true,
				dataForm:{},
				form: {

					},
				loading: false,
				rules: {
				},
				test:false,
				YSNUM:'',
				YITMREFNUM:'',
				YLIN:0,
			}
		},
		onLoad(query) {
			this.userInfo = uni.getStorageSync('userInfo');
			this.init();
			this.test = uni.getStorageSync('test')||false;
			this.scan();
		},
		mounted() {

		  },
		methods: {
			init(){
			},
			//扫码
			scan(){
				if(this.userInfo.ID=='1'){
					var codt = 'YSPKX25060102_0905'
					var codes = codt.split('_')
					if(codes.length>2){
						this.YSNUM=codes[0];
						this.YITMREFNUM= codes[1]
						this.YLIN= codes[2]
					}else if(codes.length>1){
						this.YSNUM=codes[0];
						this.YITMREFNUM= codes[1]
					}else{
						uni.showToast({
						   title: '条形码错误',
						   icon: 'error',
						   duration: 2000
						});
					}
					this.search();
					return;
				}
				var this_=this
				dd.ready(function () {
					dd.biz.util.scan({
						type: 'all', // type 为 all、qrCode、barCode，默认是all
						onSuccess: function (data) {
							//对返回的数据进行转换
							var code=data.text || data.code || data.qrCode || data.barCode
							var codes = code.split('_')
							if(codes.length>2){
								this_.YSNUM=codes[0];
								this_.YITMREFNUM= codes[1]
								this_.YLIN= codes[2]
								this_.search();
							}else if(codes.length>1){
								this_.YSNUM=codes[0];
								this_.YITMREFNUM= codes[1]
								this_.search();
							}else{
								uni.showToast({
								   title: '条形码错误',
								   icon: 'error',
								   duration: 2000
								});
							}
						},
						onFail: function (err) {
							console.log("scan",err)
							alert(err)
						},
					});
				});
			},
			async search(){
				let GRP1 = {
					GRP1: [{
						YFLG: 2,
						YNUM: this.YSNUM,
						YLIN: this.YLIN,
						}],
					GRP3: [{
							YITMREFNUM: this.YITMREFNUM,
					}],
				}
				let GRP1Json = JSON.stringify(GRP1)
				let res = await this.$api.x3.x3request("WSLISTYSP8",GRP1)
				let curData=JSON.parse(res.message);
				if (curData.GRP4.WOK!=0){
					uni.showToast({
					   title: curData.GRP4.WRESULT,
					   icon: 'error',
					   duration: 2000
					});
					return
				}
				this.dataForm=curData.GRP1;
				this.tableDataAll=curData.GRP3;
				if(this.tableDataAll.length>0){
					  this.dataForm.YITMREFNUM=this.tableDataAll[0].YITMREFNUM
					  this.dataForm.YITMREF=this.tableDataAll[0].YITMREF
					  this.dataForm.YQTY=this.tableDataAll[0].YQTY
					  this.dataForm.YSAMPGG=this.tableDataAll[0].YSAMPGG
					  this.dataForm.YSAMPFX=this.tableDataAll[0].YSAMPFX
					  this.dataForm.YSAMPLOC=this.tableDataAll[0].YSAMPLOC
					  this.dataForm.YDES=this.tableDataAll[0].YDES
					  this.dataForm.YTQUSR=this.tableDataAll[0].YTQUSR
					  this.dataForm.YTQUSRDES=this.tableDataAll[0].YTQUSRDES
				}
				if (this.dataForm.YTQUSR==''){
					this.syqrFlg=true;
				}
			},
			async getUserInfo(){
				let GRP1 = {
						GRP1: [{
							// ID:"1",
							PHONE: this.userInfo.PHONE,
					}]
				}
				let GRP1Json = JSON.stringify(GRP1)
				let res = await this.$api.x3.x3request("WSLISTYDUR",GRP1)
				let cxsbData = JSON.parse(res.message)
			},
			
			submit(q) {
				if (this.dataForm.YTQUSRDES==''){
					uni.showToast({
					   title: '未设置检验指标',
					   icon: 'error',
					   duration: 2000
					});
					return;
				}
				var this_ = this
				uni.showModal({
				  title: '提示',
				  content: '是否确认？',
				  success: function (res) {
				    if (res.confirm) {
				      this_.submitData(q);
				    }
				  }
				});
			},
			async submitData(param) {
				  let GRP1 = {
				  	GRP1: [{
							YFLAG:param,
							YNUM:this.dataForm.YNUM,
							YITMREFNUM:this.dataForm.YITMREFNUM,
				  			YTQUSR: this.userInfo.NAME,
							YLIN:this.YLIN
				  	}]
				  }
				  let res = await this.$api.x3.x3request("WSGENYSPC8",GRP1)
				let resR = JSON.parse(res.message)
				console.log(resR,'resR');
				// console.log(resR.GRP1.WOK,56777);
				if(resR.GRP2.WOK==0){
					// 显示创建成功的消息提示
					uni.showToast({
					   title: '提交成功:'+resR.GRP2.WRESULT,
					   icon: 'success',
					   duration: 2000
					});
				let that = this
				setTimeout(function() {
					uni.switchTab({url:"/pages/managementCenter/managementCenter"})
				}, 2000);
					this.form =''
					this.dataForm=''
					this.tableData=[]
					this.tableDataAll=[]
				}else{
					uni.showToast({
					   title: '提交失败',
					   icon: 'error',
					   duration: 2000
					});
				}
			},
		}
	}
</script>

<style>
.top{
	height: 100rpx;
	line-height: 100rpx;
	color: #13d5f6;
}
.two{
	background-color: white;
}
.two-one{
	overflow: hidden;
	margin-top: 20rpx;
	display: flex;
	justify-content: space-between;
}
.two-oneLeft{
	width: 190rpx;
	color: gray;
	text-align: right;
}
.two-oneRight{
	width: 350rpx;
	color: gray;
	text-align: left;
	margin-left: 10rpx;
}
.two-one1{
	overflow: hidden;
	margin-top: 20rpx;
	display: flex;
}
.two-oneLeft1{
	width: 200rpx;
	color: gray;
	text-align: right;
}
.two-oneRight1{
	color: gray;
	text-align: left;
	margin-left: 10rpx;
}
.there{
	height: 100rpx;
	line-height: 100rpx;
	color: #13d5f6;
}
.four{
	height: 120rpx;
	background-color: white;
}
.four-one{
	height: 60rpx;
	display: flex;
	justify-content: space-between;
}
.four-oneLeft{
	width: 190rpx;
	line-height: 68rpx;
	color: gray;
	text-align: right;
}
.four-oneRight{
	width: 350rpx;
	line-height: 68rpx;
	color: gray;
	text-align: left;
}
.five{
	height: 100rpx;
	line-height: 100rpx;
	color: #13d5f6;
}
.sixBox{
	height: 70rpx;
	background-color: white;
	line-height: 37rpx;
	padding-left: 40rpx;
	margin-bottom: 20rpx;
}
.four-item{
	width: 90%;
	margin-top: 16rpx;
	margin-left: 40rpx;
}
</style>
